<template>
  <div class="app-container">
    <IncreServiceFeeField ref="openIncreServiceFeeField" @refresh="refresh"></IncreServiceFeeField>
    <el-form @submit.native.prevent :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="收费项目" prop="xm">
        <el-select
            v-model="queryParams.xm"
            placeholder="请选择收费项目"
            clearable
            style="width: 240px"
            @change="changeIncreServiceFee"
            :loading="increServiceFeeItemLoading"
        >
            <el-option
                v-for="item in itemIncreServiceFee"
                :key="item.id"
                :label="item.name"
                :value="item.name"
            />
        </el-select>
     </el-form-item>
     <el-form-item label="发生日期" prop="happenDate">
        <el-date-picker
            v-model="happenDate"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="happenDateChange()">
            </el-date-picker>
      </el-form-item>
      <el-form-item label="客户" prop="khmc">
        <el-select
            v-model="queryParams.khmc"
            placeholder="请输入客户"
            clearable
            @change="changeSelectClient3"
            filterable
            :loading="selectClient3Loading"
        >
          <el-option
              v-for="(item, index) in client3List"
              :key="index"
              :label="item.khmc"
              :value="item.khmc"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="仓库" prop="spckmc">
        <el-select
            v-model="queryParams.spckid"
            placeholder="请选择"
            clearable
            @change="changeWarehouse"
            filterable
            :loading="selectWarehouse15Loading || loading"
        >
            <el-option
                v-for="item in warehouseList"
                :key="item.spckid"
                :label="item.spckmc"
                :value="item.spckid"
            />
        </el-select>
      </el-form-item>
      <el-form-item label="柜号/批号" prop="spgh">
        <el-input
          v-model="queryParams.spgh"
          placeholder="请输入柜号/批号"
          clearable
          @keyup.enter.native="enterClick"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="getList">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
     <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleIncreServiceFee" v-hasPermi="['zhcloud:zzfwf:add']">增加费用单</el-button>
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleIncreServiceFeeField" v-hasPermi="['zhcloud:category:modify']">费用项目设置</el-button>
        </el-col>
    </el-row>
    <el-table
      v-loading="loading"
      :data="increServiceFeeList"
    >
      <af-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100" fixed="left">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleOpenDetail(scope.row)"
            v-hasPermi="['zhcloud:zzfwf:list']"
          >费用明细</el-button>
        </template>
      </af-table-column>
      <af-table-column label="收费项目" align="center" prop="xm" />
      <af-table-column label="增值服务单号" align="center" prop="pzbh" />
      <af-table-column label="收费单价" align="center" prop="bzdj" />
      <af-table-column label="收费标准" align="center" prop="bz" />
      <af-table-column label="吨数" align="center" prop="spsl" />
      <af-table-column label="金额" align="center" prop="sfje" />
      <af-table-column label="发生日期" align="center" prop="rqid" />
      <af-table-column label="仓库" align="center" prop="spckmc" />
      <af-table-column label="客户" align="center" prop="allName" />
      <af-table-column label="备注" align="center" prop="itbz"   width="150" :show-overflow-tooltip="true"/>
    </el-table>
     <pagination
        v-show="total>0"
        :total="total"
        :page.sync="pageNum"
        :limit.sync="pageSize"
        @pagination="getList"
      />
  </div>

</template>

<script>
import { listIncreServiceFee, increServiceFeeItem } from "@/api/storage/commonGoods/increServiceFee";
import { selectWarehouse15 } from "@/api/storage/warehouse"
import { selectClient3 } from "@/api/storage/customer"
import IncreServiceFeeField from "./increServiceFeeField.vue";

export default {
  name: "IncreServiceFee",
  components: { IncreServiceFeeField },
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      //列表加载
      loading: true,
      //客户加载
      selectClient3Loading: true,
      //仓库加载
      selectWarehouse15Loading:true,
      //收费项目加载
      increServiceFeeItemLoading:true,
      happenDate:'',
      // 查询参数
      queryParams: {
        khmc: "",
        pzbh: "",
        rqid1: "",
        rqid2: "",
        spgh: "",
        xm: "",
        spckid:"",
        spgh:""
      },
      //获取客户参数
      selectClient3Query: {
        name1:""
      },
      //增值服务收费数据
      increServiceFeeList:[],
      //增值项目
      itemIncreServiceFee:[],
      //客户列表
      client3List: [],
      //仓库列表
      warehouseList:[],
      //批量审核数据
      selection:[],
      //页数
      pageSize: 10,
      //页码
      pageNum:1,
      // 总条数
      total: 0,
    };
  },
  beforeRouteEnter(to, from, next) {
    const params = to.params
    next(vm => {   
      if(Object.keys(params).length > 0) {
        if(to.params.refresh == true) {
          vm.getList()
        }
      }
    })
  },
  created() {
    this.getIncreServiceFeeItem()
    this.getClient3()
    this.getList()
    this.getWarehouse()
  },
  methods: {
    /**获取客户 */
    getClient3() {
      this.selectClient3Loading = true
      selectClient3(this.selectClient3Query).then(response => {
        this.client3List = response.data
        this.selectClient3Loading = false
      });
    },
    /**获取收费项目 */
    getIncreServiceFeeItem() {
      this.increServiceFeeItemLoading=true
      increServiceFeeItem({}).then(response => {
        this.itemIncreServiceFee = response.data
        this.increServiceFeeItemLoading=false
      });
    },
    /** 查询增值服务收费列表 */
    getList() {
      this.loading=true
      listIncreServiceFee(this.queryParams, {pageNum:this.pageNum, pageSize:this.pageSize}).then(response => {
        this.increServiceFeeList = response.rows;
        this.total = response.total;
        this.loading=false
      });
    },

    /**获取仓库 */
    getWarehouse() {
      this.selectWarehouse15Loading = true
      selectWarehouse15({}).then(response => {
        this.warehouseList = response.data
        this.selectWarehouse15Loading = false
      });
    },

      /**选择仓库 */
    changeWarehouse(id) {
      this.queryParams.spckid = id
      this.getList()
    },

    /**选择收费项目 */
    changeIncreServiceFee() {
      this.getList()
    },

     /**选择发生时间 */
    happenDateChange() {
      this.queryParams.rqid1 = this.happenDate?this.happenDate[0]:""
      this.queryParams.rqid2 = this.happenDate?this.happenDate[1]:""
      this.getList()
    },
    /** 增加增值服务费用*/
    handleIncreServiceFee() {
      this.$router.push({name:"IncreServiceFeeAdd"})
    },

    /** 增值服务字段*/
    handleIncreServiceFeeField() {
      this.$refs.openIncreServiceFeeField.open()
    },

    /**详情 */
    handleOpenDetail(row) {
      const data = JSON.parse(JSON.stringify(row))
      this.$router.push({path:"/storage/commonGoods/increServiceFee/increServiceFeeDetail", query:data})
    },
      /**选择客户 */
    changeSelectClient3() {
        this.getList()
    },
     /**enter键触发 */
    enterClick(e) {
      this.getList()
    },
    //刷新
    refresh() {
      this.getList()
    },
    
    /** 重置按钮操作 */
    resetQuery() {
      this.reset()
      this.getIncreServiceFeeItem()
      this.getClient3()
      this.getList()
    },
    reset() {
      Object.assign(this.$data, this.$options.data())
    },
  }
};
</script>
